﻿using System.Globalization;
using System.IO;
using System.Windows.Data;

namespace _02_TreeViews_and_Value_Converters
{
	public class HeaderConverter : IValueConverter
	{
		public static readonly HeaderConverter Instance = new HeaderConverter();

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			var result = "";
			var folder = value.ToString()?.Split("\\").LastOrDefault();
			if (string.IsNullOrWhiteSpace(folder))
			{
				result = "磁盘";
			}
			else if (File.Exists(value.ToString()) && !Directory.Exists(value.ToString()))
			{
				result = "文件";
			}
			else
			{
				result = "文件夹";
			}
			return result;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
